import React, { useEffect } from "react";
import Left from "../Left/Left.jsx";
import Right from "../Right/Right.jsx";
import { useLocation, useNavigate } from "react-router-dom";
import "./index.css";
export default function Home() {
  
  const { state } = useLocation();
  const [username, setUsername] = React.useState();
  const Navigate = useNavigate(); //在函数式组件中使用钩子函数，useNavigate的返回值是一个函数，该函数才是我们要用的东西
  useEffect(() => {
    console.log(state);
    if (!state) {
      Navigate("/login");
      return;
    }
    setUsername(state.username);
  });

  return (
    <>
      {state ? (
        <div className="main">
          <Left username={username}></Left>
          <Right username={username}></Right>
        </div>
      ) : (
        ""
      )}
    </>
  );
}
